package com.hntxk.cqzd.export.controller;/**
 * @ClassName: ${user}
 * @Author:liuqing
 * @Description
 * @Date: Created in 15:56 2020/9/22
 * @Modified By:
 */

import com.alibaba.fastjson.JSON;
import com.hntxk.core.framework.action.BaseController;
import com.hntxk.cqzd.export.model.ExcelExportConstant;
import com.hntxk.cqzd.export.model.LaboratoryExport;
import com.hntxk.cqzd.export.model.QueryParamModel;
import com.hntxk.cqzd.export.service.LaboratoryExportService;
import com.hntxk.cqzd.export.util.ExcelUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ClassName LaboratoryExportController
 * @description 实验室检查结果导出web层
 * @Author Liuqing
 * @Date 2020/9/22 15:56
 * @Version 1.0
 */
@Api(value="实验室信息导出", tags={"[SP]实验室信息导出"})
@Controller
@RequestMapping("cqzd/Laboratory")
@Slf4j
public class LaboratoryExportController  extends BaseController {

    private final LaboratoryExportService service;

    @Autowired
    public LaboratoryExportController(@Qualifier("laboratoryService") LaboratoryExportService service) {
        super();
        this.service = service;
    }

    @ResponseBody
    @RequestMapping(value = "/selLaboratoryAll" ,method = RequestMethod.GET)
    public String selLaboratoryAll(@ModelAttribute QueryParamModel model, HttpServletResponse response){
        List<LaboratoryExport> laboratoryExports = service.selLaboratoryAll(model);
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ExcelUtil.generateExcelSaveLocal(laboratoryExports,
                ExcelExportConstant.LABORATORY_TITLE,
                ExcelExportConstant.LABORATORY_FIELD,
                response,formatter.format(currentTime).replace(" ","-").replace(":","-"));
        return JSON.toJSONString("success");
    }
}
